import request from '@/utils/request'

// 获取角色列表
export const getRoleListAPI = (query) => {
  return request({
    method: 'get',
    url: '/sys/role',
    params: query
  })
}

/**
 * 删除角色
 * @param {String} id 角色id
 * @returns Promise
 */
export const delRolesAPI = (id) => {
  return request({
    method: 'delete',
    url: `/sys/role/${id}`
  })
}

/**
 * 新增角色
 *
 * @returns Promise
 */
export const addRoleAPI = (roleForm) => {
  return request({
    method: 'post',
    url: '/sys/role',
    data: roleForm
  })
}

/**
 * 获取角色详情
 * @returns Promise
 */
export const getRoleAPI = (id) => {
  return request({
    method: 'get',
    url: `/sys/role/${id}`
  })
}

// 修改角色信息
export const editRoleAPI = (roleForm) => {
  return request({
    method: 'put',
    url: `/sys/role/${roleForm.id}`,
    data: roleForm
  })
}

// 获取公司详情信息
export const getCompanyAPI = (id) => {
  return request({
    method: 'get',
    url: `/company/${id}`
  })
}

/**
 * 给角色分配权限
 * @param {String} id
 * @param {Array} permId
 * @returns Promise
 */
export const assignPremAPI = (id, permIds) => {
  return request({
    method: 'put',
    url: '/sys/role/assignPrem',
    data: {
      id,
      permIds
    }
  })
}
